<?php


namespace Frieza\Modules\RiskContent\Controllers;

use App\Http\Controllers\Controller;
use App\Pockets\GridDataModel;
use Doraemon\model\AdmUserType;
use Doraemon\model\Answer;
use Doraemon\model\Article;
use Doraemon\model\Member;
use Doraemon\model\Photos;
use Doraemon\service\RiskContent\RiskContentInfo;
use Doraemon\service\ToBan;
use Encore\Admin\Layout\Content;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Grid\Displayers\DropdownActions;
use Encore\Admin\Widgets\Tab;
use Encore\Admin\Layout\Row;
use Encore\Admin\Widgets\Table;
use Encore\Admin\Grid\Tools\BatchActions;
use Frieza\Modules\RiskContent\Actions\BatchForbidden;
use Frieza\Modules\RiskContent\Actions\ForbiddenUser;
use Frieza\Modules\RiskContent\Actions\Ignore;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;

class ToBanController extends Controller
{
    const PAGE_SIZE = 20;
    public function index(Request $request, Content $content)
    {
        $page = $request->input("page", 1);

        $start = ($page - 1) * self::PAGE_SIZE;
        $data = ToBan::toBanList($start);
        $list = $data['lists'];
        $count = $data['count'];
        $gridModel = new GridDataModel($list, $count, ['perPage' => self::PAGE_SIZE]);
        $gridList = Admin::grid($gridModel,
            function (Grid $grid) use ($gridModel) {
                $grid->disableExport();
                $grid->disableCreateButton();
                $grid->disableFilter();
                $grid->setActionClass(DropdownActions::class);
                $grid->perPages([]);
                $grid->column('uid', 'uid')->sortable()->display(function() {
                    return "<a href='/admin/user/Detail/$this->uid' target='_blank' >" . $this->uid . "</a>";
                });
                $grid->column('nick', '昵称');
                $grid->column('avatar', '头像')->display(function(){
                    return '<img src = "'.$this->avatar.'" width = 45px height = 45px />';
                });
                $grid->column('quality', '用户质量');
                $grid->column('identity_mark', '用户标签');
                $grid->column('addTime', '注册时间');
                $grid->column('date', '上次启动距今');
                $grid->actions(function (Grid\Displayers\Actions $actions) {
                    $actions->disableDelete();
                    $actions->disableEdit();
                    $actions->disableView();
                    $actions->append('<a href=""><i class="fa fa-eye"></i></a>');
                    $actions->add(new ForbiddenUser);
                    $actions->add(new Ignore);

                });

                $grid->tools(function (Grid\Tools $tools) {
                    $tools->batch(function (Grid\Tools\BatchActions $actions) {
                        $actions->disableDelete();
                        $actions->add('批量封禁', new BatchForbidden(1));
                    });
                });


            });

        return $content
            ->header('一键封禁')
            ->description(' ')
            ->breadcrumb(['text' => '一键封禁'])
            ->row($gridList);


    }
}